function InvoiceView() {
	this.parent();
}

InvoiceView.inherits(BaseView, {
	init : function() {
		this.createInvoiceView(this.ctrl.model.orderList);
	},
	createInvoiceView : function(data) {
		var key = "invoice";
		addActive(key);
		var root = $id("invoiceContent");
		root.innerHTML = "";
		if (data.length > 0) {
			var nodeTable = createTable();
			nodeTable.setAttribute("id", "tableInvoice");

			var nodeThId = createNode("th");
			var idTh = createTextNode("Mã Hóa Đơn");
			nodeThId.appendChild(idTh);
			var nodeThAcc = createNode("th");
			var accTh = createTextNode("Tài khoản");
			nodeThAcc.appendChild(accTh);
			var nodeThTotal = createNode("th");
			var totalTh = createTextNode("Tổng tiền");
			nodeThTotal.appendChild(totalTh);
			var nodeThDate = createNode("th");
			var dateTh = createTextNode("Ngày mua hàng");
			nodeThDate.appendChild(dateTh);
			// var nodeThRelease = createNode("th");
			// var releaseTh = createTextNode("Ngày giao hàng");
			// nodeThRelease.appendChild(releaseTh);
			var nodeThStt = createNode("th");
			var SttTh = createTextNode("Tình trạng");
			nodeThStt.appendChild(SttTh);
			var nodeThDetails = createNode("th");
			
			var nodeThDelete = createNode("th");
			
			nodeTable.appendChild(nodeThId);
			nodeTable.appendChild(nodeThAcc);
			nodeTable.appendChild(nodeThTotal);
			nodeTable.appendChild(nodeThDate);
			//nodeTable.appendChild(nodeThRelease);
			nodeTable.appendChild(nodeThStt);
			nodeTable.appendChild(nodeThDetails);
			nodeTable.appendChild(nodeThDelete);

			for (var i = 0, j = data.length; i < j; i++) {
				var order = data[i]
				var row = document.createElement("tr");
				row.setAttribute("id", "orderIdInRow" + order.orderId);
				//cho từng column
				// this.orderId = orderId;
				// this.ownerId = ownerId;
				// this.totalPrice = totalPrice;
				// this.orderDate = orderDate;
				// this.dateReceive = dateReceive;
				// this.status = status;

				//column orderId
				var columnOrderId = document.createElement("td");
				var id = document.createTextNode(order.orderId);
				columnOrderId.appendChild(id);
				row.appendChild(columnOrderId);

				//cột owner Name

				var columnOwnerId = document.createElement("td");
				var owner = document.createTextNode(order.userId);
				columnOwnerId.appendChild(owner);
				row.appendChild(columnOwnerId);

				// cột total price

				var columnTotalPrice = document.createElement("td");
				var totalPrice = document.createTextNode(order.totalPrice);
				columnTotalPrice.appendChild(totalPrice);
				row.appendChild(columnTotalPrice);

				//cột order date

				var columnOrderDate = document.createElement("td");
				var orderDate = document.createTextNode(order.orderDate);
				columnOrderDate.appendChild(orderDate);
				row.appendChild(columnOrderDate);				

				//cột status

				var columnStatus = document.createElement("td");
				var status = order.status;
				var statusString;
				if(status=='0'){
					statusString = "Chưa xử lý";
					status = document.createTextNode(statusString);
				} else if(status=='1'){
					statusString = "Đã xử lý";
					status = document.createTextNode(statusString);
				}
				columnStatus.appendChild(status);
				row.appendChild(columnStatus);

				//cột detail
				var columnDetail = document.createElement("td");
				var divDetail = createDiv();
				divDetail.addClass("orderDetail");
				var detail = document.createElement("span");
				var chuaXuly = document.createTextNode("Chi tiết");
				detail.style.cursor = "pointer";
				detail.style.color = "blue";
				detail.appendChild(chuaXuly);
				divDetail.appendChild(detail);
				columnDetail.addEventListener("click", function(event) {
					var currentrow = $id(event.currentTarget.parentNode.id);
					var cels = currentrow.getElementsByTagName("td");
					var id = cels[0].innerText;					
					getOrderDetail(id);
				});

				columnDetail.appendChild(divDetail);
				row.appendChild(columnDetail);
				
				nodeTdDelete = createNode("td");
				nodeDivDelete = createDiv();
				nodeDelete = createNode("img");
				nodeDelete.setAttribute("src", Pages.params.img + "delete_icon.png");
				nodeDelete.style.cursor = "pointer";
				nodeTdDelete.addEventListener("click", function(event) {
					var row = $id(event.currentTarget.parentNode.id);
					var cels = row.getElementsByTagName("td");
					var orderId = cels[0].innerText;
					var r = confirm("Bạn có muốn xóa đơn hàng có mã là " + orderId + " ?");
					if (r == true) {
						deleteOrder(orderId);
					}
				});
				nodeDivDelete.appendChild(nodeDelete);
				nodeTdDelete.appendChild(nodeDivDelete);
				row.appendChild(nodeTdDelete);
				
				nodeTable.appendChild(row);
			};
			root.appendChild(nodeTable);

			var divPaging = createDiv();
			divPaging.setAttribute("id", "pageInvoice");
			divPaging.setAttribute("class", "paging");
			var script = createNode("script");
			script.setAttribute("type", "text/javascript");
			script.innerHTML = "var pager = new Pager('tableInvoice', 10); pager.init(); pager.showPageNav('pager', 'pageInvoice'); pager.showPage(1);";
			root.appendChild(divPaging);
			root.appendChild(script);
		}
	}
});
